use version 13.1
set more off
capture log close
log using pennings_2003.log, replace

* Replication do-file for
* Schneider, Carsten Q. and Ingo Rohlfing (2014): 
* Case Studies Nested in Fuzzy-Set Qca on Sufficiency: Formalizing Case Selection and Causal Inference
* Sociological Methods & Research advance access: dx.doi.org/10.1177/0049124114532446
* If you have any questions or comments, please get in touch with:
* Carsten Schneider (schneiderc@ceu.hu) or Ingo Rohlfing (rohlfing@bigsss.uni-bremen.de)

insheet using pennings_2003.csv, comma clear /* Importing  data from your working directory, see on data footnote 7 in text */
rename fall country
label var country "Country"
rename c consdem 
label var consdem "Consensus democracy"
rename n newdem
label var newdem "New democracy"
rename p semipres
label var semipres "Semi-presidentialism"
rename r rigconst
label var rigconst "Rigid constitution"
rename k constcon
label var constcon "Constitutional control (Y)"

drop if country == "Russian Fed" /* Dropped because of missing data */

gen sd = (_n-1)/10 in 1/11	/* Variable needed for enhanced XY plots */
label var sd "Secondary diagonal"

*** Solution for sufficiency (table 2):
* 			consdem*~semipres	+	~semipres*newdem*~rigconst ->	constcon
*			(term 1)				(term 2)
*			(cons: .77)				(cons: .84)						(cons sol .75)
*			(raw cov: .69)			(raw cov: .57)					(cov sol .80)
*			(unique cov: .23)		(unique cov: .11)

*** Determining membership in terms and solution
gen p_1 = min(consdem, 1-semipres)
label var p_1 "Membership in term 1"

gen p_2 = min(1-semipres, newdem, 1-rigconst)
label var p_2 "Membership in term 2"

gen sol = max(p_1, p_2)
label var sol "Membership in solution"

*** Determining types of membership 
gen p_1_u = cond(p_1 > 0.5 & p_2 < 0.5, 1, 0)
label var p_1_u "Unique member term 1"

gen p_2_u = cond(p_1 < 0.5 & p_2 > 0.5, 1, 0)
label var p_2_u "Unique member term 2"

gen j_m = cond(p_1 > 0.5 & p_2 > 0.5, 1, 0)
label var j_m "Joint member"

gen n_m = cond(p_1 < 0.5 & p_2 < 0.5, 1, 0)
label var n_m "Non-member"

*** Determining types of cases
* Typical cases
gen p_1_t = cond(p_1 > 0.5 & constcon > 0.5 & constcon >= p_1, 1, 0)
label var p_1_t "Typ. case term 1"

gen p_1_t_u = cond(p_1 > 0.5 & constcon > 0.5 & constcon >= p_1 & p_2 < 0.5, 1, 0)
label var p_1_t_u "Typ. unique case term 1"

gen p_2_t = cond(p_2 > 0.5 & constcon > 0.5 & constcon >= p_2, 1, 0)
label var p_2_t "Typ. case term 2"

gen p_2_t_u = cond(p_2 > 0.5 & constcon > 0.5 & constcon >= p_2 & p_1 < 0.5, 1, 0)
label var p_2_t_u "Typ. unique case term 2"

gen t_j = 1 if p_1_t == 1 & p_2_t == 1
replace t_j = 1 if p_1_t == 1 & p_2 > 0.5 & p_2 > constcon
replace t_j = 1 if p_2_t == 1 & p_1 > 0.5 & p_1 > constcon
replace t_j = 0 if t_j == .
label var t_j "Typical joint members"

* Deviant cases consistency in degree
gen p_1_dd = cond(p_1 > 0.5 & constcon > 0.5 & p_1 > constcon, 1, 0)
label var p_1_dd "Dev. consistency degree term 1"

gen p_1_dd_u = cond(p_1 > 0.5 & constcon > 0.5 & p_1 > constcon & p_2 < 0.5, 1, 0)
label var p_1_dd_u "Dev. consistency degree unique term 1"

gen p_2_dd = cond(p_2 > 0.5 & constcon > 0.5 & p_2 > constcon, 1, 0)
label var p_2_dd "Dev. consistency degree term 2"

gen p_2_dd_u = cond(p_2 > 0.5 & constcon > 0.5 & p_2 > constcon & p_1 < 0.5, 1, 0)
label var p_2_dd_u "Dev. consistency degree unique term 2"

gen dd_j = cond(p_1_dd == 1 & p_2_dd == 1, 1, 0)
replace dd_j = 1 if p_1 > 0.5 & p_2 > 0.5 & p_1 < constcon & p_2 > constcon
replace dd_j = 1 if p_1 > 0.5 & p_2 > 0.5 & p_1 > constcon & p_2 < constcon
label var dd_j "Dev. consistency degree joint member"

* Deviant cases consistency in kind
gen p_1_dk = cond(p_1 > 0.5 & constcon < 0.5, 1, 0)
label var p_1_dk "Dev. consistency kind term 1"

gen p_1_dk_u = cond(p_1 > 0.5 & constcon < 0.5 & p_2 < 0.5, 1, 0)
label var p_1_dk_u "Dev. consistency kind unique term 1"

gen p_2_dk = cond(p_2 > 0.5 & constcon < 0.5, 1, 0)
label var p_2_dk "Dev. consistency kind term 2"

gen p_2_dk_u = cond(p_2 > 0.5 & constcon < 0.5 & p_1 < 0.5, 1, 0)
label var p_2_dk_u "Dev. consistency kind unique term 2"

gen dk_j = cond(p_1 > 0.5 & p_2 > 0.5 & constcon < 0.5, 1, 0)
label var dk_j "Dev. consistency kind joint member"

* Deviant cases coverage
gen dcov = cond(p_1 < 0.5 & p_2 < 0.5 & constcon > 0.5, 1, 0)
label var dcov "Dev. coverage"

* Individually irrelevant cases
gen iir = cond(p_1 < 0.5 & p_2 < 0.5 & constcon < 0.5, 1, 0)
label var iir "Individually irrelevant case"

*** Aggregating types
* Typical cases
gen typ = 0
label var typ "Typical cases"
foreach v of varlist p_1_t_u p_2_t_u t_j {
	quietly: replace typ = 1 if `v' == 1
}


gen dconsd = 0
label var dconsd "Deviant cases cons. degree"
foreach v of varlist p_1_dd_u p_2_dd_u dd_j {
	quietly: replace dconsd = 1 if `v' == 1
}


gen dconsk = 0
label var dconsk "Deviant cases cons. kind"
foreach v of varlist p_1_dk_u p_2_dk_u dk_j {
	quietly: replace dconsk = 1 if `v' == 1
}

gen dcons = 0
label var dcons "Deviant cases cons."
foreach v of varlist p_1_dd_u p_2_dd_u p_1_dk_u p_2_dk_u {
	quietly: replace dcons = 1 if `v' == 1
}

*** Designation of cases (table 3)
tab country if p_1_t_u == 1	/* Unique typical & member of term 1 */
tab country if p_2_t_u == 1	/* Unique typical & member of term 2 */
tab country if t_j == 1	/* Bulgaria and Israel are listed here because they are
	typical for one term and deviant consistency in degree for the other.
	They are only listed for term 1 in table 3 */
tab country if dconsd == 1	/* Deviant consistency in degree */
tab country if dconsk == 1	/* Deviant consistency in kind */
tab country if dcov == 1	/* Deviant coverage */
tab country if iir == 1	/* Individually irrelevant cases */

*** Plot for term 1 (consdem*~semipres) with all types of cases (figure 1)
gen sol_min = min(p_1, p_2) if t_j == 1 & dd_j == 1	/* Needed because of Bulgaria and Israel */
label var sol_min "Minimum membership in sol. for mixed-member types of Y"

twoway scatter constcon p_1 if p_1_t_u == 1, ///
	ms(o) mc(gs0) ///
	legend(label(1 "Typical & unique members term 1") order(1 2 3 4 5 6 7) rows(4) col(2) size(small) region(color(gs16))) || ///
scatter constcon sol if t_j == 1 & dd_ != 1, ///
	ms(+) mc(gs0) ///
	legend(label(2 "Typical & joint members") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///	
scatter constcon sol if dconsd == 1, ///
	ms(oh) mc(gs0) ///
	legend(label(3 "Dev. consistency in degree") order(1 2 3 4 5 6 7) rows(4) col(2)  size(small)) || ///
scatter constcon sol if p_1_dk == 1, ///
	ms(d) mc(gs0) ///
	legend(label(4 "Dev. consistency in kind term 1") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///
scatter constcon sol if p_2_dk == 1, ///
	ms(dh) mc(gs8) ///
	legend(label(5 "Dev. consistency in kind term 2") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///
scatter constcon sol if dcov == 1, ///
	ms(s) mc(gs8) ///
	legend(label(6 "Deviant coverage") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///
scatter constcon sol if iir == 1, ///
	ms(t) mc(gs8) ///
	legend(label(7 "Individually irrelevant") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///
scatter constcon sol_min if t_j == 1 & dd_j == 1, ///
	ms(+) mc(gs0) ///
	legend(label(8 "Typical & joint members") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///	
scatter constcon sol if t_j == 1 & dd_j == 1, ///
	ms(oh) mc(gs0) ///
	legend(label(9 "Dev. cons. degree & joint members") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///
scatter sd sd , ms(i) c(l) lc(gs8) legend(label(10 "Secondary diagonal")) ///
	xline(0.5, lc(gs8) lp(dash_dot)) xlabel(0(0.1)1, labsize(small)) ///
	yline(0.5, lc(gs8) lp(dash_dot)) ylabel(0(0.1)1, labsize(small)) ///
	xtitle("Membership in {it:CONSDEM*~SEMIPRES}", size(small) margin(small)) ///
	ytitle("Membership in {it:CONSTCON}", size(small) margin(small)) ///
	text(0.54 0.515 "{it:1}", size(small)) text(0.54 0.56 "{it:2}", size(small)) ///
	text(0.47 0.515 "{it:3}", size(small)) text(0.47 0.485 "{it:4}", size(small)) ///
	text(0.47 0.44 "{it:4}", size(small)) text(0.54 0.485 "{it:5}", size(small)) ///
	scheme(s1color)
graph export pennings_p_1.emf, replace
graph save pennings_p_1.gph, replace

* Preparation of plots with truth table row CONSDEM*SEMIPRES*NEWDEM*~RIGCONST
gen row_15 = 1 if consdem > 0.5 & semipres > 0.5 & newdem > 0.5 & rigconst < 0.5 
label var row_15 "Member of truth table row 15 in table 1 (main text)"

gen row_15_mem = min(consdem, semipres, newdem, (1-rigconst)) if row_15 == 1
label var row_15_mem "Membership in row 15"

*** Plot for term 1 (consdem*~semipres) with all types of cases and members of row 15 highlighted (figure 2)
twoway scatter constcon p_1 if p_1_t_u == 1, ///
	ms(o) mc(gs0) ///
	legend(label(1 "Typical & unique members term 1") order(1 2 3 4 5 6 7 8) rows(3) col(2) size(small) region(color(gs16))) || ///
scatter constcon sol if t_j == 1 & dd_j != 1, ///
	ms(+) mc(gs0) ///
	legend(label(2 "Typical & joint members") order(1 2 3 4 5 6 7 8) rows(3) col(2) size(small)) || ///	
scatter constcon sol if dconsd == 1, ///
	ms(oh) mc(gs0) ///
	legend(label(3 "Dev. consistency in degree") order(1 2 3 4 5 6 7 8) rows(3) col(2)  size(small)) || ///
scatter constcon sol if p_1_dk == 1, ///
	ms(d) mc(gs0) ///
	legend(label(4 "Dev. consistency in kind term 1") order(1 2 3 4 5 6 7 8) rows(3) col(2) size(small)) || ///
scatter constcon sol if p_2_dk == 1, ///
	ms(dh) mc(gs8) ///
	legend(label(5 "Dev. consistency in kind term 2") order(1 2 3 4 5 6 7 8) rows(3) col(2) size(small)) || ///
scatter constcon sol if dcov == 1 & row_15 != 1, ///
	ms(s) mc(gs8) ///
	legend(label(6 "Deviant coverage") order(1 2 3 4 5 6 7 8) rows(3) col(2) size(small)) || ///
scatter constcon sol if iir == 1 & row_15 != 1, ///
	ms(t) mc(gs8) ///
	legend(label(7 "Individually irrelevant") order(1 2 3 4 5 6 7 8) rows(3) col(2) size(small)) || ///
scatter constcon sol if row_15 == 1, ///
	ms(s) mc(gs0) mlab(country) mlabpos(12) mlabc(gs0) ///
	legend(label(8 "Member of {it: CONSDEM*SEMIPRES*NEWDEM*~RIGCONST}") order(1 2 3 4 5 6 7 8) ///
	rows(3) col(2) size(vsmall)) || ///
scatter constcon sol_min if t_j == 1 & dd_j == 1, ///
	ms(+) mc(gs0) ///
	legend(label(9 "Typical & joint members") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///	
scatter constcon sol if t_j == 1 & dd_j == 1, ///
	ms(oh) mc(gs0) ///
	legend(label(10 "Dev. cons. degree & joint members") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///
scatter sd sd , ms(i) c(l) lc(gs8) legend(label(11 "Secondary diagonal")) ///
	xline(0.5, lc(gs8) lp(dash_dot)) xlabel(0(0.1)1, labsize(small)) ///
	yline(0.5, lc(gs8) lp(dash_dot)) ylabel(0(0.1)1, labsize(small)) ///
	xtitle("Membership in {it:CONSDEM*~SEMIPRES}", size(small) margin(small)) ///
	ytitle("Membership in {it:CONSTCON}", size(small) margin(small)) ///
	text(0.54 0.515 "{it:1}", size(small)) text(0.54 0.56 "{it:2}", size(small)) ///
	text(0.47 0.515 "{it:3}", size(small)) text(0.47 0.485 "{it:4}", size(small)) ///
	text(0.47 0.44 "{it:4}", size(small)) text(0.54 0.485 "{it:5}", size(small)) ///
	scheme(s1color)
graph export pennings_p_1_row15.emf, replace
graph save pennings_p_1_row15.gph, replace

*** Row-based plot for row 15 of truth table (figure 3)
twoway scatter constcon row_15_mem if row_15 == 1 & dcov == 1 & country != "Poland", ///
	ms(o) mc(gs0) mlab(country) mlabpos(3) mlabcolor(gs0) mlabgap(*2) ///
	legend(label(1 "Deviant case coverage for solution") order(1 2) rows(1) size(small) region(color(gs16))) || ///
scatter constcon row_15_mem if row_15 == 1 & dcov != 1, ///
	ms(o) mc(gs8) mlab(country) mlabpos(3) mlabcolor(gs0) ///
	legend(label(2 "IIR case for solution") order(1 2) rows(1) size(small)) || ///	
scatter constcon row_15_mem if row_15 == 1 & dcov == 1 & country == "Poland" , ///
	ms(o) mc(gs0) mlab(country) mlabpos(12) mlabcolor(gs0) mlabgap(*2) ///
	legend(label(3 "Deviant case coverage for solution") order(1 2) rows(1) size(small)) || ///
scatter sd sd , ms(i) c(l) lc(gs8) legend(label(9 "Secondary diagonal")) ///
	xline(0.5, lc(gs8) lp(dash_dot)) xlabel(0(0.1)1, labsize(small)) ///
	yline(0.5, lc(gs8) lp(dash_dot)) ylabel(0(0.1)1, labsize(small)) ///
	xtitle("Membership in row  {it:CONSDEM*SEMIPRES*NEWDEM*~RIGCONST}", size(small) margin(small)) ///
	ytitle("Membership in {it:CONSTCON}", size(small) margin(small)) ///
	text(0.54 0.515 "{it:1}", size(small)) text(0.54 0.56 "{it:2}", size(small)) ///
	text(0.47 0.515 "{it:3}", size(small)) text(0.47 0.485 "{it:4}", size(small)) ///
	text(0.47 0.44 "{it:4}", size(small)) text(0.54 0.485 "{it:5}", size(small)) ///
	scheme(s1color)
graph export pennings_row_15.emf, replace
graph save pennings_row_15.gph, replace

*******************************************************
* Formulas for case selection and corresponding plots *
*******************************************************

*** Typical cases (formula 1)
gen p_1_t_s = (constcon-p_1)/p_1 if p_1_t == 1
replace p_1_t_s = round(p_1_t_s, .01)
label var p_1_t_s "Typ. case term 1, score"

*** Plot for term 1 (consdem*~semipres) with formula scores for typical cases (figure 4)
twoway scatter constcon p_1 if p_1_t_u == 1, ///
	ms(o) mc(gs0) mlab(p_1_t_s) mlabcolor(gs0) mlabpos(9) ///
	text(0.80 0.87 "Latvia", size(small)) ///
	legend(label(1 "Typical & unique members term 1") order(1 2 3 4 5 6 7) rows(4) col(2) size(small) region(color(gs16))) || ///
scatter constcon sol if t_j == 1 & dd_j != 1, ///
	ms(+) mc(gs0) ///
	legend(label(2 "Typical & joint members") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///	
scatter constcon sol if dconsd == 1, ///
	ms(oh) mc(gs0) ///
	legend(label(3 "Dev. consistency in degree") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///
scatter constcon sol if p_1_dk == 1, ///
	ms(d) mc(gs0) ///
	legend(label(4 "Dev. consistency in kind term 1") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///
scatter constcon sol if p_2_dk == 1, ///
	ms(dh) mc(gs8) ///
	legend(label(5 "Dev. consistency in kind term 2") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///
scatter constcon sol if dcov == 1, ///
	ms(s) mc(gs8) ///
	legend(label(6 "Deviant coverage") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///
scatter constcon sol if iir == 1, ///
	ms(t) mc(gs8) ///
	legend(label(7 "Individually irrelevant") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///
scatter constcon sol_min if t_j == 1 & dd_j == 1, ///
	ms(+) mc(gs0) ///
	legend(label(8 "Typical & joint members") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///	
scatter constcon sol if t_j == 1 & dd_j == 1, ///
	ms(oh) mc(gs0) ///
	legend(label(9 "Dev. cons. degree & joint members") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///
scatter sd sd , ms(i) c(l) lc(gs8) legend(label(10 "Secondary diagonal") rows(4) col(2)) ///
	xline(0.5, lc(gs8) lp(dash_dot)) xlabel(0(0.1)1, labsize(small)) ///
	yline(0.5, lc(gs8) lp(dash_dot)) ylabel(0(0.1)1, labsize(small)) ///
	xtitle("Membership in {it:CONSDEM*~SEMIPRES}", size(small) margin(small)) ///
	ytitle("Membership in {it:CONSTCON}", size(small) margin(small)) ///
	text(0.54 0.515 "{it:1}", size(small)) text(0.54 0.56 "{it:2}", size(small)) ///
	text(0.47 0.515 "{it:3}", size(small)) text(0.47 0.485 "{it:4}", size(small)) ///
	text(0.47 0.44 "{it:4}", size(small)) text(0.54 0.485 "{it:5}", size(small)) ///
	scheme(s1color)
graph export pennings_p_1_t_s.emf, replace
graph save pennings_p_1_t_s.gph, replace

*** Deviant cases consistency in kind (formula 2)
gen p_1_dk_s = (1-(p_1-constcon))/p_1 if p_1_dk == 1
replace p_1_dk_s = round(p_1_dk_s, .01)
label var p_1_dk_s "Dev. case kind term 1, score"

*** Plot for term 1 (consdem*~semipres) with formula scores for deviant cases consistency in kind (figure 5)
twoway scatter constcon p_1 if p_1_t_u == 1, ///
	ms(o) mc(gs0) ///
	legend(label(1 "Typical & unique members term 1") order(1 2 3 4 5 6 7) rows(4) col(2) size(small) region(color(gs16))) || ///
scatter constcon sol if t_j == 1 & dd_j != 1, ///
	ms(+) mc(gs0) ///
	legend(label(2 "Typical & joint members") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///	
scatter constcon sol if dconsd == 1, ///
	ms(oh) mc(gs0) ///
	legend(label(3 "Dev. consistency in degree") order(1 2 3 4 5 6 7) rows(4) col(2)  size(small)) || ///
scatter constcon p_1 if p_1_dk_u == 1, ///
	ms(d) mc(gs0) mlab(p_1_dk_s) mlabcolor(gs0) mlabpos(12) ///
	text(0.12 0.96 "Belgium", size(small)) ///
	legend(label(4 "Dev. consistency in kind term 1") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///
scatter constcon p_2 if p_2_dk_u == 1, ///
	ms(dh) mc(gs8) ///
	legend(label(5 "Dev. consistency in kind term 2") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///
scatter constcon sol if dcov == 1, ///
	ms(s) mc(gs8) ///
	legend(label(6 "Deviant coverage") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///
scatter constcon sol if iir == 1, ///
	ms(t) mc(gs8) ///
	legend(label(7 "Individually irrelevant") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///
scatter constcon sol_min if t_j == 1 & dd_j == 1, ///
	ms(+) mc(gs0) ///
	legend(label(8 "Typical & joint members") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///	
scatter constcon sol if t_j == 1 & dd_j == 1, ///
	ms(oh) mc(gs0) ///
	legend(label(9 "Dev. cons. degree & joint members") order(1 2 3 4 5 6 7) rows(4) col(2) size(small)) || ///
scatter sd sd , ms(i) c(l) lc(gs8) legend(label(10 "Secondary diagonal")) ///
	xline(0.5, lc(gs8) lp(dash_dot)) xlabel(0(0.1)1, labsize(small)) ///
	yline(0.5, lc(gs8) lp(dash_dot)) ylabel(0(0.1)1, labsize(small)) ///
	xtitle("Membership in {it:CONSDEM*~SEMIPRES}", size(small) margin(small)) ///
	ytitle("Membership in {it:CONSTCON}", size(small) margin(small)) ///
	text(0.54 0.515 "{it:1}", size(small)) text(0.54 0.56 "{it:2}", size(small)) ///
	text(0.47 0.515 "{it:3}", size(small)) text(0.47 0.485 "{it:4}", size(small)) ///
	text(0.47 0.44 "{it:4}", size(small)) text(0.54 0.485 "{it:5}", size(small)) ///
	scheme(s1color)
graph export pennings_p_1_dk_s.emf, replace
graph save pennings_p_1_dk_s.gph, replace

*** Deviant cases coverage in kind (formula 3)
gen row_15_s = (constcon-row_15_mem)/row_15_mem ///
	if constcon >= row_15_mem & row_15 == 1 
replace row_15_s = round(row_15_s, .01)
label var row_15_s "Dev. case coverage row 15, score"

*** Plot for truth table row CONSDEM*SEMIPRES*NEWDEM*~RIGCONST with formula scores (figure 5)
twoway scatter constcon row_15_mem if row_15_s != ., ///
	ms(o) mc(gs0) mlab(row_15_s) mlabcolor(gs0) mlabpos(11) mlabsize(medsmall) ///
	text(0.55 0.70 "Czech Republic & Poland", size(small)) ///
	legend(label(1 "Deviant case coverage for solution") order(1 2) rows(1) size(small) region(color(gs16))) || ///
scatter constcon row_15_mem if iir == 1 & row_15 == 1 & row_15_s == ., ///
	ms(o) mc(gs8) ///
	legend(label(2 "IIR case for solution") order(1 2) rows(1) size(small)) || ///	
scatter constcon row_15_mem if row_15_s == . & dcov == 1, ///
	ms(o) mc(gs0) ///
	legend(label(4 "Deviant case coverage for solution") order(1 2) rows(1) size(small)) || ///
scatter sd sd , ms(i) c(l) lc(gs8) legend(label(4 "Secondary diagonal")) ///
	xline(0.5, lc(gs8) lp(dash_dot)) xlabel(0(0.1)1, labsize(small)) ///
	yline(0.5, lc(gs8) lp(dash_dot)) ylabel(0(0.1)1, labsize(small)) ///
	xtitle("Membership in row  {it:CONSDEM*SEMIPRES*NEWDEM*~RIGCONST}", size(small) margin(small)) ///
	ytitle("Membership in {it:CONSTCON}", size(small) margin(small)) ///
	text(0.54 0.515 "{it:1}", size(small)) text(0.52 0.55 "{it:2}", size(small)) ///
	text(0.47 0.515 "{it:3}", size(small)) text(0.47 0.485 "{it:4}", size(small)) ///
	text(0.47 0.44 "{it:4}", size(small)) text(0.54 0.485 "{it:5}", size(small)) ///
	scheme(s1color) 
graph export pennings_row_15_s.emf, replace
graph save pennings_row_15_s.gph, replace

log close
